 <!--begin-->
<div class="section">
    <div class="section-title">LỊCH SỬ ĐẶT BÁO CỦA KHÁCH HÀNG</div>
    <?php if($_GET['print'] !="true" ){ ?>
    <div class="right">
        <a class="button print" id="btnPrint">In</a>
        <a class="button exit" href="?route=deliman/home">Đóng</a>
    </div>
	<div class="clearer">&nbsp;</div>
    <?php } ?>
    <div class="section-content padding1">
        <div>
        	<?php if($_GET['print'] !="true" ){ ?>
            <form name="frm" id="frm" action="" method="post" enctype="multipart/form-data">
                <table>
                    <thead>
                         <tr class="left">
                         	<td>
                            	<label>Số điện thoại:</label>
                                <input type="text" class="text" id="sodienthoai" name="sodienthoai"/>
                            </td>
                            <td>
                                <label>Khu vực:</label>
                                <select name="khuvucid" id="khuvucid">
                                	<option value="">Chọn tất cả</option>
                                    <?php 
                                        foreach($dskhuvuc as $khuvuc)
                                        { 
                                    ?>
                                    <option value="<?php echo $khuvuc['khuvucid']?>">
                                        <?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$khuvuc['level'])?><?php echo $khuvuc['tenkhuvuc']?>
                                    </option>
                                    <?php 
                                        }
                                    ?>
                                </select>
                            </td>
                            <td>
                                <label>Khách hàng:</label>
                                <select id="khachhangid" name="khachhangid">  
                                	<?php echo $cmbDanhSachKhachHang ?>
                                </select>
                            </td>
                            <td><a class="button-other search" onClick="searchForm()">Tìm kiếm</a></td>
                            <td><a class="button all" href="?route=deliman/lichsudatbaocuakhachhang&khuvucid=all">Xem tất cả</a></td>
                        </tr>
                       <!--<?php
                        if(trim($khachhang['khachhangid'])!='')
                        {
                       ?>
                        <tr><td><label>Thông Tin Về Khách Hàng Cần Xem </label></td></tr>
                        <tr><td><label>Họ tên: </label><label><?php echo $khachhang['hoten'] ?></label>
                            </td></tr>
                        <tr><td><label>Địa chỉ: </label><label><?php echo $khachhang['diachi'] ?></label>
                            </td></tr>
                        <tr><td><label>Điện thoại: </label><label><?php echo $khachhang['dienthoai'] ?></label>
                            </td></tr>
                        <tr><td><label>Email: </label><label><?php echo $khachhang['email'] ?></label>
                            </td></tr>
                       <?php
                        }
                       ?>-->
                    </thead>
                </table>
            </form>
            <?php } ?>
            <table class="data-table" width="100%">
                    <thead>
                        <tr>
                            <th>Tên kỳ báo</th>
                            <th>Ngày phát hành</th>
                            <th>Số lượng đặt</th>
                            <th>Số lượng đã giao</th>
                            <th>Ngày giao</th>
                            <th>Người giao</th>
                            <th>Tình trạng</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    if(isset($datas))
                    {
                        foreach($datas as $data)
                        {
                            $flag=0;                                            
                    ?>
                        <tr id="<?php echo 'kh'.$data['khachhang']['khachhangid']; ?>" >
                            <td colspan="7" style="background:#999; font-weight:bold">
                    <?php 
                          echo $data['khachhang']['masokhachhang']." - ".$data['khachhang']['hoten']." - ".$data['khachhang']['dienthoai']." - ".$data['khachhang']['diachi'];
                    ?>
                            </td>
                        </tr>
                    <?php
                            foreach($data['dsloaibao'] as $loaibao)
                            {
                                $flag = 1;
                    ?>
                    
                        <tr >
                            <th colspan="7" >
                                    <?php echo $loaibao['tenloaibao']?>
                            </th>
                        </tr>
                    
                    <?php
                              foreach($data['dskybao'] as $kybao)
                              {
                                  if($kybao['loaibaoid'] == $loaibao['loaibaoid'])
                                  {
                    ?>
                        <tr>
                            <td><?php echo $kybao['tenkybao']?></td>
                            <td>
                                <?php echo $this->date->formatMySQLDate($kybao['ngayphathanh'], 'DMY')?>
                            </td>
                            <td><?php echo $this->string->numberFormate($kybao['soluongdat'])?></td>
                            <td><?php echo $this->string->numberFormate($kybao['soluongdagiao'])?></td>
                            <td>
                                <?php echo $this->date->formatMySQLDate($kybao['ngaygiao'], 'longdate')?>
                            </td>
                            <td><?php echo $kybao['tenhanviengiao']?></td>
                            <td>
                            	<?php
                                	if(trim($kybao['trangthai'])=='chuagiao' || trim($kybao['trangthai'])=='') 
                                		echo "Chưa giao";
                                    if(trim($kybao['trangthai'])=='dagiao') 
                                		echo "Đã giao";
                                    if(trim($kybao['trangthai'])=='huy') 
                                		echo "Hủy";
                                    
                                ?>
                            </td>
                        </tr>
                    <?php
                                  }
                              }
                            }
                            if($flag==0)
                            {
                    ?>
                    <!--Ẩn đi nếu KH chưa đặt báo-->
                    <script language="javascript">
                        //$temp = "<?php echo '#kh'.$data['khachhang']['khachhangid']; ?>";
                        //$(""+$temp).hide();
                    </script>
                    
                    <!-- Hiện thông báo nếu KH chưa đặt báo
                        <tr><td colspan="7"><label>Khách hàng chưa đặt kỳ báo nào..</label></td></tr> -->
                    <?php
                            }
                    ?>
                    <tr><td colspan="7"></td></tr>
                    <?php
                        }
                    }
                    else
                    {
                    ?>
                        <tr><td colspan="7"><label>Khu vực này chưa có khách hàng nào..</label></td></tr> 
                    <?php
                    }
                    ?>    
                    </tbody>
                </table>
        </div> 
        
        <div class="clearer">&nbsp;</div>
    </div>
    
    <div class="section-bottom"></div>
</div>
<!--end-->
           
                
<script language="javascript">
	$("#khuvucid").change(function(){
		$('#khachhangid').load('?route=deliman/lichsudatbaocuakhachhang/getKhachHang&khuvucid='+$(this).val(), function(){
			$("#khachhangid").val("<?php echo $_GET['khachhangid']?>");
		});
	});
	$("#khuvucid").change();
function searchForm()
{
	var url =  "?route=deliman/lichsudatbaocuakhachhang";
	if($("#sodienthoai").val() != "")
		url += "&sodienthoai=" + $("#sodienthoai").val();
	if($("#khachhangid").val() != "")
		url += "&khachhangid=" + $("#khachhangid").val();
	if($("#khuvucid").val() != "")
		url += "&khuvucid=" + $("#khuvucid").val();
	if($("#khuvucid").val() == "" && $("#khachhangid").val() == "")
		url += "&khuvucid=all";
	
	window.location = url;
}
// Giu cho cac field tim kiem van ko doi
$("#sodienthoai").val("<?php echo $_GET['sodienthoai']?>");
$("#khuvucid").val("<?php echo $_GET['khuvucid']?>");
$("#khuvucid").change();
$('#btnPrint').click(function(){
	
	var url = window.location+"&print=true";
	 var result = window.showModalDialog(url,"", "dialogWidth:1000px; dialogHeight:450px; center:yes");
});


</script>
<?php if($_GET['print'] =="true" ){ ?>
	<script language="javascript">
        window.print();
    </script>
<?php } ?>